package cn.wsalix.sale.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.wsalix.sale.entity.SaleRecord;
import cn.wsalix.sale.form.SaleRecordForm;
import cn.wsalix.sale.repository.SaleRecordRepository;
import cn.wsalix.sale.service.SaleRecordService;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;

@Service("saleRecordService")
public class SaleRecordServiceImpl extends CommonServiceImpl<SaleRecordForm,SaleRecordRepository, SaleRecord>
		implements SaleRecordService {
	@Autowired
	private SaleRecordRepository saleRecordRepository;

	@Override
	public String module() {
		return "/sale/salerecord";
	}

	@Override
	public SaleRecordRepository getRepository() {
		return saleRecordRepository;
	}

	@Override
	public Class<SaleRecord> getEntityClazz() {
		return SaleRecord.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(SaleRecordForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		if (form.getProductId() != null && form.getProductId() != 0) {
			filters.put("productId", new SearchFilter("productId",
					Operator.EQ, form.getProductId()));
		}
		return filters;
	}

}
